/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Dec 31, 2009
 * Time: 10:58:49 AM
 * To change this template use File | Settings | File Templates.
 */
import dk.brics.automaton.Automaton;
import java.util.*;

// Referenced classes of package dk.brics.jwig.analysis.summarygraph:
//            TemplateEdge, StringEdge, Template

public class Node
{

    private Node()
    {
    }

    public Object clone()
    {
        Node node = new Node(key, xml, origin);
        node.open_gaps = (HashSet)open_gaps.clone();
        return node;
    }

    public String toString()
    {
        String s = super.toString();
        return "N" + s.substring(s.indexOf(64) + 1);
    }

    public Node(Object obj, Template template, Object obj1)
    {
        key = obj;
        xml = template;
        origin = obj1;
        template_edges = new HashMap();
        string_edges = new HashMap();
        open_gaps = new HashSet();
    }

    public void addTemplateEdge(TemplateEdge templateedge)
    {
        TemplateEdge templateedge1 = (TemplateEdge)template_edges.get(templateedge);
        if(templateedge1 == null)
            template_edges.put(templateedge, templateedge);
        else
            templateedge1.origins.addAll(templateedge.origins);
    }

    public void addStringEdge(StringEdge stringedge)
    {
        StringEdge stringedge1 = lookupStringEdge(stringedge.gap);
        if(stringedge1 == null)
        {
            string_edges.put(stringedge.gap, stringedge);
        } else
        {
            stringedge1.origins.addAll(stringedge.origins);
            stringedge1.labels = stringedge1.labels.union(stringedge.labels);
            stringedge1.labels.minimize();
        }
    }

    public Object getKey()
    {
        return key;
    }

    public Template getTemplate()
    {
        return xml;
    }

    public Object getOrigin()
    {
        return origin;
    }

    public boolean addOpenGap(String s)
    {
        return open_gaps.add(s);
    }

    public void addAllOpenGaps()
    {
        open_gaps.addAll(xml.getAttributeGaps());
        open_gaps.addAll(xml.getTemplateGaps());
    }

    public boolean removeOpenGap(String s)
    {
        return open_gaps.remove(s);
    }

    public Set getOpenGaps()
    {
        return open_gaps;
    }

    Map cloneTemplateEdges(Map map)
    {
        HashMap hashmap = new HashMap();
        TemplateEdge templateedge1;
        for(Iterator iterator = template_edges.values().iterator(); iterator.hasNext(); hashmap.put(templateedge1, templateedge1))
        {
            TemplateEdge templateedge = (TemplateEdge)iterator.next();
            templateedge1 = (TemplateEdge)templateedge.clone();
            templateedge1.to = (Node)map.get(templateedge.getDestination().getKey());
        }

        return hashmap;
    }

    Map cloneStringEdges()
    {
        HashMap hashmap = new HashMap();
        StringEdge stringedge;
        for(Iterator iterator = string_edges.values().iterator(); iterator.hasNext(); hashmap.put(stringedge.gap, stringedge))
        {
            stringedge = (StringEdge)iterator.next();
            stringedge = (StringEdge)stringedge.clone();
        }

        return hashmap;
    }

    public Collection lookupTemplateEdges(String s)
    {
        ArrayList arraylist = new ArrayList();
        Iterator iterator = template_edges.values().iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            TemplateEdge templateedge = (TemplateEdge)iterator.next();
            if(templateedge.gap.equals(s))
                arraylist.add(templateedge);
        } while(true);
        return arraylist;
    }

    public TemplateEdge lookupTemplateEdge(Node node, String s)
    {
        TemplateEdge templateedge = new TemplateEdge(node, s, (Object)null);
        return (TemplateEdge)template_edges.get(templateedge);
    }

    public StringEdge lookupStringEdge(String s)
    {
        return (StringEdge)string_edges.get(s);
    }

    public Collection getTemplateEdges()
    {
        return template_edges.values();
    }

    public Collection getStringEdges()
    {
        return string_edges.values();
    }

    public Collection getReverseEdges()
    {
        return reverse_edges;
    }

    Object key;
    Template xml;
    Map template_edges;
    Map string_edges;
    Object origin;
    HashSet open_gaps;
    Set reverse_edges;
}
